/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.jili.ubert.clientapi;

import com.jili.ubert.clientapi.until.UnWorkException;
import com.jili.ubert.code.client2server.RequestPageData;
import com.jili.ubert.code.server2client.MsgResult;
import com.jili.ubert.code.server2client.PageDataProto;
import com.jili.ubert.code.server2client.Price;
import com.jili.ubert.dao.db.OrderExecuteProgress;
import com.panemu.tiwulfx.common.TableData;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 *
 * @author dragon
 */
public class MarketDataRequest {

    private DataPool dataPool;
    private MarketDataNettyClient client;

    public MarketDataRequest() {
        client = new MarketDataNettyClient();
    }
    public MarketDataRequest(String host, int port) {
        this.client = new MarketDataNettyClient();
        MsgResult ret = client.Connect(host, port, false, false, this);
        if (!ret.getSuccess()) {
            throw new UnWorkException(ret.getWord());
        }
    }
    public MsgResult Connect(String host, int port, boolean isSSL, boolean isZlib) {
        return client.Connect(host, port, isSSL, isZlib, this);
    }
    public void setDataPool(DataPool datapool) {
        this.dataPool = datapool;
    }
    private final SessionBucket sessionBucket = new SessionBucket();
    private final ListenPriceBucket listenPriceBucket = new ListenPriceBucket(128);
    //2.构造函数
    private AtomicInteger requstid = new AtomicInteger(0);

    private int getRequstID() {
        if (requstid.getAndIncrement() == Integer.MAX_VALUE) {
            requstid.getAndSet(Integer.MIN_VALUE);
        }
        return requstid.intValue();
    }
    public void AccpetSessionAnswer(int id, MsgEntity msg) {
        this.sessionBucket.OnDealSession(id, msg);
    }

    public void AccpetSessionFaileAnswer(int id, MsgResult msg) {
        this.sessionBucket.OnFaile(id, msg);
    }
    public void OnPrice(Price price){
        listenPriceBucket.OnDealListen(price);
    }

}
